package com.hp.java09_springboot.service;

import com.hp.java09_springboot.mapper.UserMapper;
import com.hp.java09_springboot.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.selectAll();
    }

    @Override
    public User findById(String userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public void save(User user) {
        user.setUserId(UUID.randomUUID().toString().substring(0,8));
        userMapper.insert(user);
    }

    @Override
    public void modify(User user) {
        userMapper.update(user);
    }

    @Override
    public void remove(String userId) {
        userMapper.delete(userId);
    }
}
